package com.anhtuan.reminder.tasks;

import com.anhtuan.reminder.services.NotifyService;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

public class StopAlarmTask implements Runnable {

	// System alarm manager
	private final AlarmManager alarmManager;
	// Context to retrieve the alarm manager
	private final Context context;
	// Id to identify the alarm
	private final int requestCode;
	
	public StopAlarmTask(int requestCode, Context context) {
		this.context = context;
		this.alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
		this.requestCode = requestCode;
	}
	
	@Override
	public void run() {
		
		Intent intent = new Intent(context, NotifyService.class);
		intent.putExtra(NotifyService.INTENT_STOP, true);
		PendingIntent pendingIntent = PendingIntent.getService(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
		
		alarmManager.cancel(pendingIntent);
	}

}
